//minxins.js 文件



export default {
    data() {
        return {
            message: '混入对象',
            foo: 'foo',
            pages: {
                list: [],
                pageSize: 12,
                pageNum: 1,
                total: 0,
                pages: 1
            },
            searchText: '',
            newXn: [],
            newXj: [],
            newZy: [],
            bjListNew: [],
            rules: {
                schooldId: [{
                    required: true,
                    message: '请选择学校',
                    trigger: 'change'
                }],
                xnxq: [{
                    required: true,
                    message: '请选择学年学期',
                    trigger: 'change'
                }],
                xj: [{
                    required: true,
                    message: '请选择学级',
                    trigger: 'change'
                }],
                zy: [{
                    required: true,
                    message: '请选择专业',
                    trigger: 'change'
                }],
                trId: [{
                    required: true,
                    message: '请选择教师',
                    trigger: 'change'
                }]
            },
            form: {
                xnxq: '',
                xj: '',
                zy: '',
                searchText: '',
                trId: null,
                schooldId: null,
                trName: ''
            },
        }
    },
    created() {
        this.teamxxlb()
        this.jyzXnxqlistNew()
    },
    methods: {
        //远程搜索
        remoteMethod(query) {
            if (query !== '') {
                this.searchText = query
                this.teamxxlb()
            }
        },
        //加载学校
        loadMore() {
            if (this.pages.pageNum < this.pages.pages) {
                this.pages.pageSize += 12;
                this.teamxxlb()
            } else {
                // this.pages.pageSize = 12
            }
        },
        // 加载老师
        loadMoreTr() {
            if (this.page.pageNum < this.page.pages) {
                console.log(this.page);
                this.page.pageSize = this.page.pageSize + 10;
                this.schoolTrList()

            } else {
                // this.page.pageSize = 10
            }
        },
        // 深度克隆
        deepClone(obj) {
            var objClone = Array.isArray(obj) ? [] : {};
            if (obj && typeof obj === "object") {
                for (i in obj) {
                    if (obj.hasOwnProperty(i)) {
                        if (obj[i] && typeof obj[i] === "object") {
                            objClone[i] = deepClone(obj[i]);
                        } else {
                            objClone[i] = obj[i];
                        }
                    }
                }
            }
            return objClone;
        },

        schoolTrList() {
            var params = {
                schoolid: this.form.schooldId,
                searchtext: this.form.searchText,
                pageNum: this.page.pageNum,
                pageSize: this.page.pageSize
            };
            this.$api.jyz.schoolTrList(params).then(res => {
                if (res.code == '0') {
                    this.page = res.list;
                    if (res.list.list.length > 0) {
                        this.form.trId = res.list.list[0].id
                        this.form.trName = res.list.list[0].name
                        console.log(this.form.trName);
                    } else {
                        this.form.trId = ''
                        this.form.trName = ''
                    }

                } else {
                    this.$message.error('操作失败！');
                }
            })
        },
        
        resetForm(formName) {
            this.$refs[formName].resetFields();
        },
        //查询服务团队学校列表
        teamxxlb() {
                this.loading = true;
            let params = {
                searchText: this.searchText,
                pageNum: this.pages.pageNum,
                schoolid: this.schoolid,
                pageSize: this.pages.pageSize
            };
            this.$ajax.post('/yschool/teampagelist', params).then(res => {
                this.loading = false;
                if (res.code == '0') {
                    this.pages = res.list;
                    // this.form.schooldId = res.list.list[0].id
                    this.schoolTrList()
                } else {
                    this.$message.error('请求失败！');
                }
            })
        },
        jyzXnxqlistNew() {
            this.$api.jyz.jyzXnxqlist({
                schoolid: this.form.schooldId
            }).then(res => {
                // console.log(res);
                if (res.code == '0') {
                    this.newXn = res.list;
                    // this.newXn = this.deepClone(res.list)
                    res.list.map(resp => {
                        if (resp.isCur == 1) {
                            this.form.xnxq = resp.xn + resp.xq;
                        }
                    })
                    this.getXjListDataNew();
                } else {
                    this.$message.error('请求失败！');
                }
            })
        },
        getXjListDataNew() {
            let params = {
                schoolid: this.form.schooldId
            };
            this.$api.jyz.getXj(params).then(res => {
                if (res.code == '0') {
                    this.newXj = res.list;
                    // this.form.xj = res.list[0];
                    this.getZyListNew();
                } else {
                    this.$message.error('请求失败！');
                }
            })
        },
        getZyListNew() {
            if (this.form.schooldId == null) return;
            let params = {
                schoolid: this.form.schooldId
            };
            this.$api.jyz.getZyList(params).then(res => {
                if (res.code == '0') {
                    this.newZy = res.list;
                    // this.form.zy = res.list[0].zydm;
                    // this.schoolClassListNew()
                } else {
                    this.$message.error('请求失败！');
                }
            })
        },
        schoolClassListNew() {
            let params = {
                schoolid: this.form.schooldId,
                zydm: this.form.zy,
                xn: this.form.xn,
                xq: this.form.xq,
                xj: this.form.xj
            };
            this.$api.jyz.schoolClassList(params).then(res => {
                console.log(res)
                if (res.code == '0') {
                    this.bjList = res.list;
                } else {
                    this.$message.error('请求失败！');
                }
            })
        },
        selectSchool() {
            this.schoolTrList()
            this.getZyListNew()
        },
        selectTeacher(e) {

            this.form.trName = this.page.list.find(o => o.id == e).name
            console.log(this.page.list.find(o => o.id == e).name);
        }

    }
}
